Skip to content

Conversation

@dkhaye
Copy link

@dkhaye dkhaye commented Aug 18, 2025

In this PR

  • New tests (non-breaking change that adds compatibility coverage)
  • Documentation (non-breaking change that documents the new tests)

Issues reference

  • N/A

Checklist

  • Checked there are no duplicate PRs for this change
  • Linted locally with pnpm lint
  • Explained what the changes do and why they're needed
  • Wrote new tests for core changes
  • Built locally with pnpm build
  • Tested locally with pnpm test
  • Committed using Conventional Commits

Summary

Adds comprehensive JWT compatibility tests to validate that upgrading @fastify/jwt from 9.0.1 to 9.1.0 is safe for this project. Tests exercise the plugin as used here (including JWKS-based verification, scope handling, and error behavior) without referencing package versions, ensuring forward compatibility for future upgrades. Also adds documentation describing how to run and interpret the new tests.

What changed

  • Tests
    • Added test/jwt-compatibility.ts:
      • Validates plugin registration and config errors (missing JWKS_URL)
      • Verifies token decoding and formatUser behavior (with and without scope)
      • Ensures read/write scope authorization works and denies when missing
      • Covers malformed/invalid tokens and auth header edge cases
      • Exercises integration with artifact upload/download/HEAD
      • Confirms issuer/audience matching when configured
  • Docs
    • Added docs/jwt-compatibility-testing.md explaining:
      • What's covered by the tests
      • How to run them and troubleshoot failures
      • Why this protects future plugin upgrades

Why this is needed

  • Confirms that moving from @fastify/jwt 9.0.1 → 9.1.0 does not change behavior in this codebase
  • Provides a safety net for future @fastify/jwt upgrades by testing usage patterns rather than versions
  • Ensures compatibility with JWKS verification via fastify-jwt-jwks and scope-based access checks

How to verify locally

  • Run only the new tests:
pnpm test jwt-compatibility.ts
  • Run the full suite:
pnpm test
  • Build and type-check:
pnpm run build
pnpm run check:types

Notes on compatibility

  • The tests validate the behavior expected by this repo's integration:
    • JWT validation via JWKS (mocked with mock-jwks)
    • Optional issuer/audience matching
    • Scope-based route authorization for read/write
    • Consistent error handling for auth header issues and invalid tokens

These assertions are stable and independent of specific @fastify/jwt versions, so they will continue to guard behavior as the dependency evolves.

@socket-security
Copy link

socket-security bot commented Aug 18, 2025

Caution

Review the following alerts detected in dependencies.

According to your organization's Security Policy, you must resolve all "Block" alerts before proceeding. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Block Low
@azure/[email protected] has URL strings.

URLs: https://storage.azure.com/.default, https://disk.compute.azure.com/.default, Microsoft.Storage

Location: Package overview

From: package.jsonnpm/@azure/[email protected]

ℹ Read more on: This package | This alert | What are URL strings?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Review all remote URLs to ensure they are intentional, pointing to trusted sources, and not being used for data exfiltration or loading untrusted code at runtime.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@azure/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Block Low
@azure/[email protected] has URL strings.

URLs: Microsoft.Storage

Location: Package overview

From: pnpm-lock.yamlnpm/@azure/[email protected]npm/@azure/[email protected]

ℹ Read more on: This package | This alert | What are URL strings?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Review all remote URLs to ensure they are intentional, pointing to trusted sources, and not being used for data exfiltration or loading untrusted code at runtime.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@azure/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Block Low
@fastify/[email protected] has a New author.

New Author: eomm

Previous Author: gurgunday

From: pnpm-lock.yamlnpm/@fastify/[email protected]npm/[email protected]npm/@fastify/[email protected]

ℹ Read more on: This package | This alert | What is new author?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Scrutinize new collaborator additions to packages because they now have the ability to publish code into your dependency tree. Packages should avoid frequent or unnecessary additions or changes to publishing rights.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@fastify/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Block Low
[email protected] has URL strings.

URLs: lcov.info, https://istanbul.js.org/, http://cobertura.sourceforge.net/xml/coverage-04.dtd

Location: Package overview

From: pnpm-lock.yamlnpm/[email protected]npm/[email protected]

ℹ Read more on: This package | This alert | What are URL strings?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Review all remote URLs to ensure they are intentional, pointing to trusted sources, and not being used for data exfiltration or loading untrusted code at runtime.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

See 4 more rows in the dashboard

View full report

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR upgrades @fastify/jwt from version 9.0.1 to 9.1.0 and adds comprehensive compatibility tests to ensure the upgrade is safe and to protect against future breaking changes.

  • Adds extensive JWT compatibility test suite covering all JWT authentication features
  • Documents the new compatibility testing approach for future upgrades
  • Upgrades the @fastify/jwt dependency to version 9.1.0

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/jwt-compatibility.ts Comprehensive test suite covering JWT plugin registration, token validation, scope authorization, error handling, storage integration, and configuration validation
package.json Updates @fastify/jwt dependency from 9.0.1 to 9.1.0
docs/jwt-compatibility-testing.md Documentation explaining the JWT compatibility testing approach, test categories, and troubleshooting guidance

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dkhaye dkhaye requested a review from Copilot September 22, 2025 12:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +475 to +487
// First upload an artifact
await app.inject({
method: 'PUT',
url: `/v8/artifacts/${artifactId}`,
headers: {
authorization: `Bearer ${token}`,
'content-type': 'application/octet-stream',
},
query: {
team,
},
payload: Buffer.from('test cache data'),
})
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This artifact upload code is duplicated in multiple test cases. Consider extracting it into a helper function to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +112
console.log('JWT token rejected:', response.body)
assert.fail('JWT token should be valid but was rejected')
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using console.log in tests is not recommended as it pollutes test output. Consider using the test runner's built-in assertion messages or removing this debug output entirely.

Suggested change
console.log('JWT token rejected:', response.body)
assert.fail('JWT token should be valid but was rejected')
assert.fail(`JWT token should be valid but was rejected. Response body: ${response.body}`)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant